<style scoped>
  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }
  .weui-loadmore_line .weui-loadmore__tips {
    background-color: #eee;
  }
  .rj-cell.max span{
    font-size: 16px;
    padding-right: 20px;
  }
  .rj-cell label {
    color: #333;
    font-size: 14px;
    width: 44%;
    display: inline-block;
    padding: 5px 3%;
    text-align: right;
  }
  .rj-cell span {
    font-size: 14px;
    color: #333;
    display: inline-block;
    width: 50%;
  }
  .rj-cell.note label{
    float: left;
  }
  .rj-cell.note span{
    width: 80%;
    display: inline-block;
  }
  .weui-cells {
    margin-top: 0;
  }
  .weui-cells_form {
    background: #fbfbfb;
  }
  .weui-cell {
    background: #fff;
  }
  .weui-cells__title {
    text-align: left;
  }
  .oitem {
    padding: 3px;
  }
  .hide {
    display: none;
  }
  #acts {
    font-size: 0;
  }
  #acts span {
    font-size: 14px;
  }
  .halfbtn {
    display: inline-block;
    width: 49%;
  }
  .weui-label {
    text-align: left;
  }

  .weui_uploader_input_wrp {
    float: left;
    position: relative;
    margin-right: 9px;
    margin-bottom: 9px;
    width: 77px;
    height: 77px;
    border: 1px solid #D9D9D9;
  }
  .weui_uploader_hd {
    padding-top: 0;
    padding-right: 0;
    padding-left: 0;
  }
  .weui_uploader_files {
    list-style: none;
  }
  .weui_uploader_input_wrp:before {
    width: 2px;
    height: 39.5px;
  }
  .weui_uploader_input_wrp:before, .weui_uploader_input_wrp:after {
    content: " ";
    position: absolute;
    top: 50%;
    left: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    background-color: #D9D9D9;
  }
  .weui_uploader_input {
    position: absolute;
    z-index: 1;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  }
  .weui_uploader_input_wrp:after {
    width: 39.5px;
    height: 2px;
  }
  .weui_uploader_bd {
    overflow: hidden;
  }
  .weui_cell {
    padding: 10px 15px;
    position: relative;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    background: #fff;
  }
  .examine >>> .weui-uploader_files {
    list-style: none;
    overflow-y: hidden;
  }
  .weui-cell_select {
    padding: 0 15px;
  }


  .weui-panel {
    background: #eee;
  }

  .rj-cont-tit {
    margin: 0;
    border-radius: 0;
  }

  .weui-panel {
    margin-top: 0;
    text-align: left;
  }

  .hd .weui-grid.js_grid {
    font-weight: 600;
  }

  .weui-grid.js_grid {
    width: 25%;
    padding: 10px 1px;
  }

  /*.weui-grid.fir {*/
  /*  width: 20%;*/
  /*}*/
  /*.weui-grid.sec {*/
  /*  width: 15%;*/
  /*}*/
  /*.weui-grid.thr {*/
  /*  width: 20%;*/
  /*}*/
  /*.weui-grid.fou {*/
  /*  width: 15%;*/
  /*}*/
  /*.weui-grid.fiv {*/
  /*  width: 15%;*/
  /*}*/
  .weui-grid__label {
    text-overflow: initial;
  }
  .section {
    margin: 5px;
    border-radius: 5px;
  }
  .btoms {
    width: 100%;
    position: fixed;
    bottom: 0;
  }

  .weui_uploader_input_wrp.inrow {
    width: 30px;
    height: 30px;
    margin: 0;
  }

  .weui_uploader_input_wrp:before {
    height: 19.5px;
  }

  .weui_uploader_input_wrp:after {
    width: 19.5px;
  }

  .weui-uploader_file.inrow {
    margin: 0;
    width: 40px;
  }

  li.weui-uploader_file {
    display: inline-block;
    padding: 3px 5px;
  }

  ul#images {
    text-align: right;
  }
  .section {
    margin: 5px;
    border-radius: 5px;
  }
  .weui-select {
    height: auto;
    line-height: inherit;
  }
</style>
<template>
  <div class="refuse" style="height: 100%;background: #eee;overflow: hidden;">
    <div class="rj-wrap" style="background: #fff;">
      容错处理
      <a href="javascript:;" @click="$router.back(-1)" style="position: absolute; left: 10px; top: 8px">
        <img src="@/assets/back.png" style="width: 20px" />
      </a>
    </div>
    <div class="tops">
        <div class="weui-cell">
          <div class="weui-cell__hd"><label class="weui-label">业务流程</label></div>
          <div class="weui-cell__bd">
            <select class="weui-select" v-model="flow" placeholder="请选择流程">
              <option value="" style="color: #ccc;" disabled>请选择</option>
              <option v-for="item in flows" :value="item.id">{{item.name}}</option>
            </select>
          </div>
        </div>
        <div class="weui-cell">
          <div class="weui-cell__hd"><label class="weui-label">订单编号</label></div>
          <div class="weui-cell__bd" style="display: flex;align-items: center;">
            <input class="weui-input" type="text" v-model="code" placeholder="请输入订单编号" style="width: 70%;" />
            <a href="javascript:;" @click="getOrder" class="weui-btn weui-btn_primary" style="width: 25%;font-size: 12px;">查询</a>
          </div>
        </div>
    </div>
    <div class="conts section">
      <div class="weui-form-preview" v-for="(item, index) in orders" :key="item.id" :ref="item.id"  style="background: #fff;border-radius: 5px;">
<!--        <div class="weui-form-preview__hd">-->
<!--          <label class="weui-form-preview__label">业务类型</label>-->
<!--          <em class="weui-form-preview__value">{{item.noticeTitle}}</em>-->
<!--        </div>-->
        <div class="weui-form-preview__bd">
          <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">订单编号</label>
            <span class="weui-form-preview__value">{{item.code}}</span>
          </div>
          <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">发起人</label>
            <span class="weui-form-preview__value">{{item.createName}}</span>
          </div>
          <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">发起时间</label>
            <span class="weui-form-preview__value">{{item.createtime}}</span>
          </div>
        </div>
        <div class="weui-form-preview__ft" style="line-height: 50px;" >
          <a class="weui-form-preview__btn weui-form-preview__btn_primary" v-for="(node, index) in item.nodes" :key="node.guid" href="javascript:" @click="postForm(item.id, node.id, node.flowtempId)" >{{node.name}}</a>
        </div>
      </div>
      <div class="weui-loadmore weui-loadmore_line" v-if="orders.length == 0">
        <span class="weui-loadmore__tips">没有数据哦~</span>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
  name: 'CommonRefuse',
  data () {
    return {
      submitStat: false,
      openid: localStorage.openid,
      flows: [],
      flow: '',
      orders: [],
      code: '',
      opinion: ''
    }
  },
  mounted () {
    this.getFlows();
  },
  methods: {
    resetData() {
      this.code = '';
      this.orders = [];
    },
    getFlows: async function() {
      let that = this;
      await this.axios({
        method: 'get',
        url: '/prod-api/flow/flowtemp/newList',
        params: {}
      }).then(response => {
        if (response.data.code == 200) {
          this.flows = response.data.data;
        } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
          //不不设置提示
        } else {
          this.toastText('获取业务流程数据失败!');
        }
      });
    },
    getOrder(code) {
      if (!this.flow) {
        this.toastText('请先选择业务流程')
        return;
      }
      //  this.orders = [{"id":203,"code":"PF220439","orgId":null,"toOrgId":null,"deptId":168,"status":100,"condition":null,"createName":"13600000008","createBy":55,"updateBy":null,"createTime":null,"updateTime":null,"remark":"","businessType":null,"baseItems":null,"cusCtractId":null,"projectId":null,"projId":null,"supplierId":null,"fullName":null,"params":null,"busTable":null,"orgFlag":null,"guid":"0cd49625641c48439cceae8f37b49e85","purchdate":"2022-04-24","orgid":"162AE70D01A6427D916688DA1374D0EF","orgname":"集宁工厂","departid":"8DA919C976254DDC863FDD887F3BFEA6","department":"原料中心-四子王旗","totalweight":null,"totalnum":100.00,"totalamount":150.00,"supplierid":"19","supplier":"山丹县田澳农机专业合作社","currency":null,"exchangerate":null,"isintax":null,"ispriceintax":null,"operatorid":"6091189BF5E74B0296AD1D952FF3BBAE","operator":"13600000008","flowtempguid":"26","srguid":"542414C110644DD9B7D0E881968B55AE","srname":"康莱纳（集宁工厂）","createtime":"2022-04-27","roomids":null,"stats":null,"items":[{"searchValue":null,"createBy":null,"createTime":null,"updateBy":null,"updateTime":null,"remark":null,"params":{},"guid":"abb469c29963487b94c3b827175f6835","purchaseguid":"0cd49625641c48439cceae8f37b49e85","productguid":"03949BC1F53E45E896B97B37117EE873","spguid":"7c328aab410245189f06962d46d1023c","productname":"中加二号","spname":"中加二号翻包薯","loadcount":null,"count":100.000000,"stockunitid":3,"stockunit":"公斤","srguid":"542414C110644DD9B7D0E881968B55AE","shrguid":null,"orgguid":"162AE70D01A6427D916688DA1374D0EF","orgname":"集宁工厂","price":1.50,"currency":null,"amount":150.00,"type":"2"}],"nodes":[{"id":7,"code":null,"orgId":null,"toOrgId":null,"deptId":null,"status":null,"condition":null,"createName":null,"createBy":null,"updateBy":null,"createTime":null,"updateTime":null,"remark":null,"businessType":null,"baseItems":null,"cusCtractId":null,"projectId":null,"projId":null,"supplierId":null,"fullName":null,"params":null,"busTable":null,"orgFlag":null,"flowtempId":26,"name":"退回库房","msgTempId":null,"operate":"back","permission":46,"flowNextStat":80,"flowStat":100,"repeatFlag":1,"sort":30,"annex":null,"nodeType":9999,"flag":null,"isSendOa":null,"refuseFlag":null,"sendTodoMsgFlag":null,"nextNodeId":null,"timeLimit":null,"supervisor":null,"remindRule":null,"operation":null,"approvalType":null,"branchiids":null,"isTransmit":null,"optlogid":null,"operators":null,"logs":null,"orderId":null,"flowtempname":null,"busistatdick":null,"permissionname":null,"nowstatusname":null,"nextstatusname":null,"nextnodaname":null,"nextnodecode":null,"nrulename":null,"flowTaskId":null,"className":"FlowTempNode"}],"depids":null,"statusname":"结束","createbyname":null,"keyword":null,"reciever_id":null,"whinitems":null,"className":"Purchasebill"}]
      // console.log('orders:', orders)
      this.axios({
        method: 'GET',
        url: '/prod-api/getRejectNodeByCode',
        params: {flowTempId: this.flow, code: this.code}
      }).then((response) => {
        //关闭提交状态
        $.hideLoading();
        if (response.data.code == 200) {
          this.orders = response.data.data ? [response.data.data] : [];
        } else if (response.data.msg) {
          this.toastText(response.data.msg);
        } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
          //不不设置提示
        } else {
          this.toastError('系统错误');
        }
      })
    },
    doAct: async function (name, id, nodeid, actname, annex, refuseflag) {
      let that = this;
      let acts = this.$store.state.acts;
      that.$router.push({name: acts[name], query: {id:id, nodeid: nodeid, title: actname, annex: annex, refuseflag: refuseflag}});
    },
    postForm: function (id, nodeid, flowid) {
      console.log('id:', id)
      console.log('nodeid:', nodeid)
      console.log('flowid:', flowid)
      let that = this;
      let addHtml = '<div class="cellgroup"> <div class="weui-cell"> <div class="weui-cell__bd"> <textarea class="weui-textarea" id="remark" name="remark" placeholder="请输处理意见" rows="2"></textarea> </div> </div> </div>';
      $.modal({
        title: '确定要执行该操作？',
        text: addHtml,
        buttons: [
          { text: "确定", onClick: function(){
              if (that.submitStat) return;
              //提交状态开始
              that.submitStat = true;
              //显示提交状态
              $.showLoading("正在提交");

              let postData = {};
              postData.id = id;
              postData.nodeId = nodeid;
              postData.flowId = flowid;
              postData.content = $('#remark').val();
              that.axios({
                method: 'post',
                url: '/prod-api/backApproval',
                params: postData
              }).then(response => {
                //恢复提交按钮可点击
                that.submitStat = false;
                //关闭提交状态
                $.hideLoading();

                if (response.data.code == 200) {
                  that.toastSuccess('操作成功!');
                  that.resetData();
                } else if (response.data.msg) {
                  that.toastText(data.msg);
                } else {
                  that.toastText('系统错误');
                }
              });
            }},
          { text: "取消", className: "default", onClick: function(){
            }},
        ]
      });
    },

}
}
</script>
